﻿using MediatR;
using TaskProject.Application.Command.BOM;
using TaskProject.Domain.BOM;
using TaskProject.ErrorCode;
using TaskProject.InfrasIntructure.Implement;
using TaskProject.InfrasIntructure.Interface;

namespace TaskProject.Application.Handler.BOM
{
    public class GetBOMOneHandler : IRequestHandler<GetBOMOneCommand, APIResult<List<BOMModel>>>
    {
        DatabaseContext db;
        IBaseRepository<BOMModel> bomRepo;

        public GetBOMOneHandler(DatabaseContext db, IBaseRepository<BOMModel> bomRepo)
        {
            this.db = db;
            this.bomRepo = bomRepo;
        }

        public Task<APIResult<List<BOMModel>>> Handle(GetBOMOneCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<BOMModel>> res = new APIResult<List<BOMModel>>();
            var boms=bomRepo.GetAll().Where(c=>c.ProductId==request.ProductId && !c.IsDel);
            res.Msg = "查询BOM成功";
            res.Code=APIEnum.Success;
            res.Data = boms.ToList();
            return Task.FromResult(res);
        }
    }
}
